<html>
<head>
<meta charset="utf-8">
<script>
function checkNumber(e)
{
    var keynum = window.event ? e.keyCode : e.which;
    //alert(keynum);
    var tip = document.getElementById("tip");
    if( (0<=keynum || keynum<=0) || keynum == 8 ){
        tip.innerHTML =  event.keyCode;
        return true;
    }else {
        tip.innerHTML = "提示：只能输入数字！";
        return false;
    }
}   
</script>
</head>
<body>
<div>请输入：<input type="text" onkeyUP="return checkNumber(event);" />
<span id="tip"></span>
</div> 
</body>
</html>